{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Turtle motion\n",
    "turtle.forward()/turtle.fd()\n",
    "\n",
    "- Parameters:distance – a number (integer or float)\n",
    "- 按照乌龟前进的方向，将乌龟向前移动指定的距离。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.00,0.00)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import turtle \n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(25.00,0.00)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.forward(25)\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-50.00,0.00)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.forward(-75)\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.back(distance)\n",
    "\n",
    "turtle.bk(distance)\n",
    "\n",
    "turtle.backward(distance)\n",
    "\n",
    "- Parameters:distance – a number\n",
    "- 向后移动乌龟一定距离，与乌龟前进的方向相反。不更改乌龟的航向。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-50.00,0.00)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-80.00,0.00)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.backward(30)\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.right(angle)/turtle.left(angle)\n",
    "\n",
    "turtle.rt(angle)/turtle.lt(angle)\n",
    "- Parameters:angle – a number (integer or float)(角度)\n",
    "- 以角度单位向右(左)转乌龟。（单位默认为度，但可以通过degree()和radians()函数进行设置。）角度方向取决于乌龟模式，请参见mode()。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "315.0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.right(45)\n",
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.left(45)\n",
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.goto(x, y=None)\n",
    "\n",
    "turtle.setpos(x, y=None)\n",
    "\n",
    "turtle.setposition(x, y=None)\n",
    "\n",
    "__Parameters__\n",
    "\n",
    "     x – a number or a pair/vector of numbers\n",
    "     \n",
    "     y – a number or None\n",
    "\n",
    "如果y为None，则x必须是一对坐标或Vec2D（例如，由pos()返回）。 将乌龟移到绝对位置。如果笔向下，则画线。不改变乌龟的方向。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-80.00,0.00)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tp = turtle.pos()\n",
    "tp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(60.00,30.00)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.setpos(60, 30)\n",
    "turtle.pos()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20.00,80.00)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.setpos((20, 80))\n",
    "turtle.pos()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-80.00,0.00)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.setpos(tp)\n",
    "turtle.pos()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.setx(x)\n",
    "\n",
    "turtle.sety(y)\n",
    "- 参数：一个整数或浮点数\n",
    "- 将乌龟的第一个坐标设置为x，第二个坐标保持不变。\n",
    "- 将乌龟的第二个坐标设置为y，第一个坐标保持不变。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-80.00,0.00)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-10.00,-10.00)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.setx(-10)\n",
    "turtle.sety(-10)\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.setheading(to_angle)\n",
    "\n",
    "turtle.seth(to_angle)\n",
    "- 参数：一个整数或浮点数\n",
    "- 将乌龟的方向设置为to_angle。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "90.0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.setheading(90)\n",
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.home()\n",
    "- 将海龟移至原点–坐标（0,0）–并将其标题设置为其开始方向（取决于模式，请参见mode（））。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.00,0.00)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.home()\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.circle(radius, extent=None, steps=None)\n",
    "- 参数：radius(半径)，extant(弧形角度),steps(步骤)\n",
    "- 画一个给定半径的圆。 中心是乌龟左侧的半径单位； 弧形角度确定绘制圆的哪一部分。 如果未给出范围，则绘制整个圆。 如果范围不是一个完整的圆，则圆弧的一个端点是当前笔的位置。 如果半径为正，则沿逆时针方向绘制弧，否则沿顺时针方向绘制弧。最终，乌龟的方向会随弧形角度改变\n",
    "- 由于圆是由内接正则多边形逼近的，因此步数决定了要使用的步数。如果未给出，它将自动计算。可用于绘制常规多边形。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.00,0.00)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.home()\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-0.00,0.00)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.circle(50)\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.00,240.00)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.circle(120, 180) # 画一个半圆\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "180.0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.dot(size=None, *color)\n",
    "- 参数：size 默认None，如果给定为 >= 1 的整数，color 颜色字符串或数字颜色元组\n",
    "- 使用颜色绘制一个直径大小的圆点。如果未指定大小，则使用pensize + 4和2 * pensize的最大值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100.00,-0.00)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.home()\n",
    "turtle.dot()\n",
    "turtle.fd(50); turtle.dot(20, \"blue\"); turtle.fd(50)\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.stamp()\n",
    "- 在当前乌龟位置将乌龟形状的副本标记在画布上。返回该图章的stamp_id，可通过调用clearstamp（stamp_id）将其删除。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.color(\"blue\")\n",
    "turtle.stamp()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.clearstamp(stampid)\n",
    "- 参数：stampid –整数，必须为上一个stamp（）调用的返回值\n",
    "- 删除具有给定图章的stampid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100.00,-0.00)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(150.00,-0.00)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.color('blue')\n",
    "astamp = turtle.stamp()\n",
    "turtle.fd(50)\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(150.00,-0.00)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.clearstamp(astamp)\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.clearstamps(n=None)\n",
    "- 删除所有或第一个/最后一个乌龟图章。如果n为None，则删除所有图章；如果n> 0，则删除前n个图章；否则，如果n <0，则删除最后n个图章。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(8):\n",
    "    turtle.stamp(); turtle.fd(30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "turtle.clearstamps(2)\n",
    "turtle.clearstamps(-2)\n",
    "turtle.clearstamps()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.undo()\n",
    "- 撤销（重复）上次乌龟动作。可用撤消操作的数量由撤消缓冲区的大小决定。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(4):\n",
    "    turtle.fd(50); turtle.lt(80)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(8):\n",
    "    turtle.undo()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.speed(speed=None)\n",
    "- 参数 speed-0..10范围内的整数或speedstring（请参见下文）\n",
    "- 将乌龟的速度设置为0..10范围内的整数。如果未提供任何参数，则返回当前速度。 \n",
    "- 如果输入的数字大于10或小于0.5，则将速度设置为0。将速度字符串映射到速度值，如下所示：\n",
    "            “fastest”: 0\n",
    "            “fast”: 10\n",
    "            “normal”: 6\n",
    "            “slow”: 3\n",
    "            “slowest”: 1\n",
    "- 从1到10的速度会强制越来越快地绘制线图和乌龟。 \n",
    "- __注意__ ：speed = 0表示没有动画发生。 前进/后退使乌龟跳跃，同样，左/右使乌龟立即转弯。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.speed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.speed('normal')\n",
    "turtle.speed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.speed(9)\n",
    "turtle.speed()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tell Turtle’s state\n",
    "turtle.position()/turtle.pos()\n",
    "- 返回乌龟的当前位置（x，y）（作为Vec2D矢量）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(390.00,-0.00)"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.pos()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.towards(x, y=None)\n",
    "- 参数：\n",
    "        x –数字或数字对/向量或乌龟实例\n",
    "        y –如果x是数字，则为数字，否则为None\n",
    "- 返回从乌龟位置到由（x，y），向量或其他乌龟指定的位置之间的线之间的角度。 这取决于乌龟的开始方向，具体取决于模式-\"standard\"/\"word\" or \"logo\"）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "225.0"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.goto(10, 10)\n",
    "turtle.towards(0, 0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.xcor()\n",
    "turtle.ycor()\n",
    "- 返回乌龟的X/Y坐标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(64.28,76.60)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.home()\n",
    "turtle.lt(50)\n",
    "turtle.fd(100)\n",
    "turtle.pos()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "64.27876\n",
      "76.60444\n"
     ]
    }
   ],
   "source": [
    "print(round(turtle.xcor(), 5))\n",
    "print(round(turtle.ycor(), 5))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.heading()\n",
    "- 返回乌龟的当前航向（值取决于乌龟模式，请参见mode（））"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "67.0"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.home()\n",
    "turtle.left(67)\n",
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.distance(x, y=None)\n",
    "- 参数：\n",
    "        x –数字或数字对/向量或乌龟实例\n",
    "        y –如果x是数字，则为数字，否则为None\n",
    "- 以乌龟步长单位返回从乌龟到（x，y），给定向量或给定其他乌龟的距离。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "50.0"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.home()\n",
    "turtle.distance(30,40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "50.0"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.distance((30,40))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Settings for measurement\n",
    "turtle.degrees(fullcircle=360.0)\n",
    "- 参数：完整的循环-一个数字\n",
    "- 设置角度测量单位，即设置一个完整的圆的“度”数。默认值为360度。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "90.0"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.home()\n",
    "turtle.left(90)\n",
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100.0"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将角度测量单位更改为grad（也称为gon，grade或gradian，等于直角的1/100。）\n",
    "turtle.degrees(400.0)\n",
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "90.0"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.degrees(360)\n",
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.radians()\n",
    "- 将角度测量单位设置为弧度。相当于度数（2 * math.pi）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "90.0"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.home()\n",
    "turtle.left(90)\n",
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.5707963267948966"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.radians()\n",
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Pen control\n",
    "# Drawing state\n",
    "turtle.pendown()\n",
    "\n",
    "turtle.pd()\n",
    "\n",
    "turtle.down()\n",
    "- 向下拉笔–移动时绘图。\n",
    "\n",
    "turtle.penup()\n",
    "\n",
    "turtle.pu()\n",
    "\n",
    "turtle.up()\n",
    "- 向上拉笔–移动时不绘画。\n",
    "\n",
    "turtle.pensize(width=None)\n",
    "\n",
    "turtle.width(width=None)\n",
    "- 参数：width - 一个正数\n",
    "- 将线条粗细设置为width或返回。 如果将resizemode设置为“ auto”，并且turtleshape是多边形，则该多边形将以相同的线宽绘制。 如果未提供任何参数，则返回当前的pensize。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.pensize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "turtle.pensize(10) # 从这里开始在宽度为10的线上绘制"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.pen(pen=None, **pendict)\n",
    "- 参数：\n",
    "        pen - 具有下面列出的一些或全部键的字典\n",
    "        pendict - 一个或多个带有以下列出的关键字作为关键字的  关键字参数\n",
    "- 使用以下键/值对在“笔字典”中返回或设置笔的属性：、\n",
    "        “shown”: True/False\n",
    "        “pendown”: True/False\n",
    "        “pencolor”: color-string or color-tuple\n",
    "        “fillcolor”: color-string or color-tuple\n",
    "        “pensize”: positive number\n",
    "        “speed”: number in range 0..10\n",
    "        “resizemode”: “auto” or “user” or “noresize”\n",
    "        “stretchfactor”: (positive number, positive number)\n",
    "        “outline”: positive number\n",
    "        “tilt”: number\n",
    "        \n",
    "- 该字典可用作后续调用pen（）的参数，以恢复以前的笔状态。此外，这些属性中的一个或多个可以作为关键字参数提供。这可用于在一个语句中设置多个笔属性。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('fillcolor', 'black'),\n",
       " ('outline', 1),\n",
       " ('pencolor', 'red'),\n",
       " ('pendown', True),\n",
       " ('pensize', 10),\n",
       " ('resizemode', 'noresize'),\n",
       " ('shearfactor', 0.0),\n",
       " ('shown', True),\n",
       " ('speed', 9),\n",
       " ('stretchfactor', (1.0, 1.0)),\n",
       " ('tilt', 0.0)]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.pen(fillcolor=\"black\", pencolor=\"red\", pensize=10)\n",
    "sorted(turtle.pen().items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('fillcolor', ''), ('outline', 1), ('pencolor', 'yellow')]"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "penstate = turtle.pen()\n",
    "turtle.color(\"yellow\", \"\")\n",
    "turtle.penup()\n",
    "sorted(turtle.pen().items())[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('fillcolor', 'green'), ('outline', 1), ('pencolor', 'red')]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.pen(penstate, fillcolor=\"green\")\n",
    "sorted(turtle.pen().items())[:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.isdown()\n",
    "- 如果笔向下，则返回True；如果笔向上，则返回False。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.penup()\n",
    "turtle.isdown()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.pendown()\n",
    "turtle.isdown()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Color control\n",
    "turtle.pencolor(*args)\n",
    "- 返回或设置笔色。 \n",
    "- 允许使用四种输入格式：\n",
    "\n",
    "    - pencolor()：返回当前的pencolor作为颜色格式字符串或元组（请参见示例）。 可用作另一个颜色/彩色/填充颜色的输入。\n",
    "    - pencolor(colorstring)：将pencolor设置为colorstring，这是Tk颜色格式字符串，例如“ red”，“ yellow”或“＃33cc8c”。\n",
    "    - pencolor((r, g, b))：将pencolor设置为r，g和b的元组表示的RGB颜色。 r，g和b的每个都必须在0..colormode范围内，其中colormode是1.0或255（请参阅colormode（））。\n",
    "    - pencolor(r, g, b)：将pencolor设置为r，g和b表示的RGB颜色。 r，g和b的每个值都必须在0..colormode范围内。\n",
    "    \n",
    "如果turtleshape是多边形，则使用新设置的pencolor绘制该多边形的轮廓。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.colormode()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'red'"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.pencolor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'brown'"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.pencolor(\"brown\")\n",
    "turtle.pencolor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.2, 0.8, 0.5490196078431373)"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tup = (0.2, 0.8, 0.55)\n",
    "turtle.pencolor(tup)\n",
    "turtle.pencolor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(51.0, 204.0, 140.0)"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.colormode(255)\n",
    "turtle.pencolor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(50.0, 193.0, 143.0)"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.pencolor('#32c18f')\n",
    "turtle.pencolor()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "turtle.fillcolor(*args)\n",
    "- 返回或设置填充颜色。\n",
    "- fillcolor()/fillcolor(colorstring)/fillcolor((r, g, b))/fillcolor(r, g, b)\n",
    "\n",
    "turtle.color(*args)\n",
    "- 返回或设置pencolor和fillcolor。\n",
    "- 允许使用几种输入格式。它们使用0到3个参数，如下所示：\n",
    "        color()\n",
    "        color(colorstring), color((r,g,b)), color(r,g,b)\n",
    "        color(colorstring1, colorstring2), color((r1,g1,b1), (r2,g2,b2))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'violet'"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.fillcolor(\"violet\")\n",
    "turtle.fillcolor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(50.0, 193.0, 143.0)"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.pencolor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(50.0, 193.0, 143.0)"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.fillcolor((50, 193, 143))  # Integers, not floats\n",
    "turtle.fillcolor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(255.0, 255.0, 255.0)"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.fillcolor('#ffffff')\n",
    "turtle.fillcolor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('red', 'green')"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.color(\"red\", \"green\")\n",
    "turtle.color()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((40.0, 80.0, 120.0), (160.0, 200.0, 240.0))"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.color(\"#285078\", \"#a0c8f0\")\n",
    "turtle.color()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Filling\n",
    "..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.00,-22.00)"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.goto(0,-22)\n",
    "turtle.left(100)\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0398314119209529"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.00,0.00)"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.reset()\n",
    "turtle.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.heading()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "turtle.write(\"Home = \", True, align=\"center\")\n",
    "turtle.write((0,0), True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "turtle.hideturtle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "turtle.showturtle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'classic'"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.shape()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'turtle'"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.shape(\"turtle\")\n",
    "turtle.shape()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'noresize'"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.resizemode()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'auto'"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.resizemode(\"auto\")\n",
    "turtle.resizemode()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1.0, 1.0, 1)"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.shapesize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5, 5, 12)"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.resizemode(\"user\")\n",
    "turtle.shapesize(5, 5, 12)\n",
    "turtle.shapesize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5, 5, 8)"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.shapesize(outline=8)\n",
    "turtle.shapesize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "turtle.shape(\"circle\")\n",
    "turtle.shapesize(5,2)\n",
    "turtle.shearfactor(0.5)\n",
    "turtle.shearfactor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
